from gluon.tools import Recaptcha


def _():
    key='login_from:%s' %request.env.remote_addr
    num_login_attemps= cahce.ram(key,lambda:0,None)
    
    if num_login_attenps >= 3:
        auth.settings.login_captcha = Recaptcha(request, '6LePaekSAAAAAC0yb9sLxwidDdoxdSFG4dcPGDuj', '6LePaekSAAAAADbDqVHazf4wwI655gBrhmYGASCE')

    def login_attempt(form,key=key,n=num_login_attemps+1):
        cache.ram(key,lambda n=n:n,0)

    def login_success(form, key=key):
        cache.ram(key,lambda:0,0)
    
    auth.settings.login_onvalidation.append(login_attempt)
    auth.settings.login_onaccept.append(login_sucess)

_()
